<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class AddressController extends Controller
{
    public function index(Request $request)
    {
        $parent_id = (int)$request->get('parent_id', 0);
        //提交了省市区信息
        $json = json_decode(file_get_contents(public_path('china_area.json')), true);
        if ($parent_id) {
            $address = $json[$parent_id] ?? [];
        } else {
            $address = $json['100000'];
        }
        $data = [];
        foreach ($address as $id => $name) {
            $item_data['id'] = $id;
            $item_data['name'] = $name;
            $data[] = $item_data;
        }
        return successReturn($data);
    }
}
